import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';

class VideoView extends StatefulWidget {
  final String url;
  const VideoView({Key? key, required this.url}) : super(key: key);

  @override
  State<VideoView> createState() {
    return _VideoViewState();
  }
}

class _VideoViewState extends State<VideoView> with AutomaticKeepAliveClientMixin{
  final FijkPlayer player = FijkPlayer();

  @override
  void initState() {
    super.initState();
    player.setDataSource(widget.url, autoPlay: true);
  }

  @override
  void dispose() {
    super.dispose();
    player.release();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return AspectRatio(
      aspectRatio: 1.6,
      child: FijkView(
        color: Colors.black,
        player: player,
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
